<?php
/*
 * 主要功能是设置和获取属性。
 *
*/
class WooControllerRequest{
	public $properties;
	//控制器类可以通过$feedback数组方便的传递消息给用户
	private $feedback = array();

	function __construct($dsn ){
		$this->init();
		//var_dump('WooControllerRequest '.$dsn);
		//WooBaseApplicationRegistry::setRequest($this);
		WooBaseApplicationRegistry::setRequest($dsn);
	}

	//init()方法负责载入私有的$properties数组，同时支持命令行参数和HTTP请求
	function init(){
		/*var_dump($_SERVER['REQUEST_METHOD'],$_SERVER['argv']);
		if(isset($_SERVER['REQUEST_METHOD'])){
			$this->properties = $_REQUEST;
			return ;
		}*/

		//foreach($_SERVER['argv'] as $arg){
		$_SERVER['argv'] = explode(',',$_SERVER['QUERY_STRING']);
		foreach($_SERVER['argv'] as $arg){
			//var_dump($arg);
			if(strpos($arg,'=')){
				list($key,$val) =  explode("=",$arg);
				$this->setProperty($key,$val);
			}
		}
	}

	//有个一个Request对象后，就可以通过getProperty() 方法获得HTTP请求中的参数
	function getProperty($key){
		if(isset($this->properties[$key])){
			return $this->properties[$key];
		}
	}


	function setProperty($key,$val){
		$this->properties[$key] = $val;
	}


	function addFeedback($msg){
		array_push($this->feedback,$msg);
	}

	function getFeedback(){
		return $this->feedback;
	}


	function getFeedbackString($separator="\n"){
		return implode($separator, $this->feedback);
	}







}